<template>
  <div>
    <transition>
      <keep-alive>
        <router-view/>
      </keep-alive>
    </transition>
    <div style="height: 50px"></div>
    <TabBar :selected="currentTab" @selectTab="onTabSelected"/>
  </div>
</template>

<script>
  import TabBar from './TabBar'


  export default {
    components: {
      TabBar,
    },
    watch: {
      routePath(val) {
        this.changeCurrentTab()
      },
    },
    data() {
      return {
        currentTab: 0,
      }
    },
    created() {
      this.changeCurrentTab()
    },
    computed: {
      routePath() {
        return this.$route.path
      }
    },
    methods: {
      changeCurrentTab() {
        if (this.$route.path.includes('/tab/home/')) {
          this.currentTab = 0
        } else if (this.$route.path.includes('/tab/university/')) {
          this.currentTab = 1
        } else if (this.$route.path.includes('/tab/huidao/')) {
          this.currentTab = 2
        } else if (this.$route.path.includes('/tab/me/')) {
          this.currentTab = 3
        } else {
          this.currentTab = 0
        }
      },
      onTabSelected(data) {
        this.currentTab = data.tab
      },
    },
  }
</script>

<style scoped>


</style>
